<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_er_account_config extends discuz_table
{
	public function __construct() {
		$this->_table = 'er_accountcenter_config';
		$this->_pk    = 'id';
		parent::__construct();
	}

	public function fetch_all($ids = array(), $force_from_db = false) {
		return DB::fetch_all("SELECT * FROM %t", array($this->_table)); 	
	}

	public function fetch_by_key($key) {
		return DB::fetch_first("SELECT * FROM %t WHERE `key`=%s", array($this->_table, $key));	
	}

	public function fetch_by_keys($keys) {
		$result = array();
		if (!empty($keys)) {
			$query = DB::query("SELECT * FROM %t WHERE `key` IN (%n)", array($this->_table, $keys));
			while ($row = DB::fetch($query)) {
				$result[$row['key']] = $row;
			}
		}
		return $result;
	}

	public function update_by_key($key, $data) {
		$result = DB::update($this->_table, $data, array('key' => $key));
		return [
			'success' => $result !== false,
			'message' => $result !== false ? '更新成功' : '更新失败',
			'code' => $result !== false ? 200 : 500
		];
	}
}